#include<cstdio>
#include<cstring>
const int maxn=1000;
bool v[maxn];
int p[maxn],r[maxn],a[maxn];
int n;
int find(int i)
{
	int k,t,j=i;
	while(p[j]!=j)j=p[j];
	for(k=i;p[k]!=k;)
	{
		t=k;
		k=p[k];
		p[t]=j;
	}
	return j;
}
void merge(int i,int j)
{
	int r1=find(i);
	int r2=find(j);
	if(r1!=r2)
	{
		if(r[r1]>r[r2])p[r2]=r1;
		else
		{
			p[r1]=r2;
			if(r[r1]==r[r2])r[r2]++;
		}
	}
}

int main()
{
	int x,y,count=0;
	scanf("%d%d",&x,&y);
	while(x!=-1)
	{
		count++;
		int node=0,edge=0;
		bool tree=true;
		memset(v,0,sizeof(v));
		for(int i=0;i<maxn;i++){p[i]=i;r[i]=1;}
		if(x!=0){
		while(x!=0)
		{
			if(!v[x]){v[x]=true;node++;}
			if(!v[y]){v[y]=true;node++;}
			edge++;
			merge(x,y);
			scanf("%d%d",&x,&y);
		}
		if(edge!=node-1)tree=false;
		else
		{
			for(int i=1;i<maxn;i++)
				if(v[i]){x=find(i);break;}
			for(int i=1;i<maxn;i++)
				if(v[i]&&find(i)!=x){tree=false;break;}
		}}
		if(tree)printf("Case %d is a tree.\n",count);
		else printf("Case %d is not a tree.\n",count);
		scanf("%d%d",&x,&y);
	}
	return 0;
}



